inherit alice cmake-utils

INS_DIR="/opt/cern/alice/aliroot"

DESCRIPTION="ALICE root"
SRC_URI=""
ESVN_PROJECT="aliroot"
HOMEPAGE="http://aliceinfo.cern.ch/Offline"

SLOT="${ALIROOT_FULL_NAME}"
LICENSE="LGPL-2.1"

KEYWORDS="amd64 x86"

IUSE="pars"
CDEPEND="$ROOT_VERSION_DEP
  $GEANT3_VERSION_DEP"

DEPEND="${CDEPEND}
  >=sci-physics/eselect-aliroot-1.2.0"

RDEPEND="${CDEPEND}"

S="${WORKDIR}/${ALIROOT_FULL_NAME}${ALIROOT_EXTRA_PAR}"

export ALICE_ROOT="${S}"
export ALICE="${WORKDIR}"

src_unpack() {
  subversion_src_unpack "$@"
}

src_configure() {
  alice_set_rootsys_env
  alice_set_geant3_env
  export ALICE_ROOT="${S}"
  export ALICE="${WORKDIR}"
  export ALICE_INSTALL="${D}/${INS_DIR}/${ALIROOT_FULL_NAME}"
  export ALICE_TARGET=`root-config --arch`
  export F77="gfortran"
#  source /var/lib/layman/alice/eclass/aliroot_env.sh
  ln -s $GEANT3 $ALICE/geant3
  export LD_LIBRARY_PATH="$ALICE/geant3/lib/tgt_$ALICE_TARGET:$LD_LIBRARY_PATH"

#   cp -R ${ESVN_STORE_DIR}/aliroot/v${ALIROOT_FULL_NAME}/.svn ${S}/
  ln -snf ${ESVN_STORE_DIR}/aliroot/v${ALIROOT_FULL_NAME}/.svn ${S}/.svn

  PREFIX=${D}/${INS_DIR}/${ALIROOT_FULL_NAME}
  mkdir -p ${WORKDIR}/${P}_build
  cd ${WORKDIR}/${P}_build
  cmake -DCMAKE_BUILD_TYPE:STRING=Debug $ALICE_ROOT
#   cmake-utils_src_configure
  einfo "OK"
}
src_compile() {
  alice_set_rootsys_env
  alice_set_geant3_env
  export ALICE_ROOT="${S}"
  export ALICE="${WORKDIR}"
  export ALICE_INSTALL="${D}/${INS_DIR}/${ALIROOT_FULL_NAME}"
  export ALICE_TARGET=`root-config --arch`
  export F77="gfortran"
  export LD_LIBRARY_PATH="$ALICE/geant3/lib/tgt_$ALICE_TARGET:$LD_LIBRARY_PATH"
  cd ${WORKDIR}/${P}_build
#   emake OPT="${CFLAGS}" F77OPT="${FFLAGS}"
#   emake OPT="${CFLAGS}" F77OPT="${FFLAGS}"
  emake OPT="${CFLAGS}" F77OPT="${FFLAGS}" || die "Compilation failed!"
  
  if use pars ; then
    emake par-all || die "Creating PAR files failed!"
  fi
#   cmake-utils_src_compile
}
src_install() {
#  cmake-utils_src_install
#  cd $ALICE/${ALIROOT_FULL_NAME}${ALIROOT_EXTRA_PAR}_build
  cd ${WORKDIR}/${P}_build
  emake install || die "Installation failed!"
  echo "$ROOT_VERSION" > ${D}/${INS_DIR}/${ALIROOT_FULL_NAME}/gentoo-aliroot-deps
  echo "$GEANT3_VERSION" >> ${D}/${INS_DIR}/${ALIROOT_FULL_NAME}/gentoo-aliroot-deps

  if use pars ; then
    mkdir -p ${D}/${INS_DIR}/${ALIROOT_FULL_NAME}/pars
    cp ${WORKDIR}/${P}_build/*.par ${D}/${INS_DIR}/${ALIROOT_FULL_NAME}/pars/ || die "Install failed!"
  fi
  rsync -r --exclude '.svn' "${S}/" "${D}/${INS_DIR}/${ALIROOT_FULL_NAME}" || die "Install failed!"
}
